//
//  BDOrderHomeViewController.m
//  BeidouMall
//
//  Created by qie on 16/4/8.
//  Copyright © 2016年 qie. All rights reserved.
//

#import "BDOrderHomeViewController.h"
#import "NinaPagerView.h"
#import "BDTransformViewController.h"
#import "BDOrderFooter.h"
#import "OrderTableViewCell.h"
#import "BDEvaluationViewController.h"
#import "BDOrderDetailViewController.h"
#import "BDRefundViewController.h"

#import "BDNavigationController.h"
#import "BDLoginTableViewController.h"

#define kPageSize 5

@interface BDOrderHomeViewController () <UITableViewDelegate,UITableViewDataSource,NinaPagerViewDelegate,BDOrderFooterDelegate,OrderTableViewCellDelegate>
{
    NSArray *_vcsArray;
    NSInteger _curPage;
    NSMutableArray *_OrderList;
    NSUInteger lastTag;
    NSDictionary *statusDic;
    UIViewController *home_vc;
    NSUInteger nowPage;
    NinaPagerView *_ninaPagerView;
    BOOL presentLoginView;
}
@end

@implementation BDOrderHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"订单";
    
    [self tableViewSettings];
    _OrderList = [[NSMutableArray alloc] init];
    
    statusDic = @{@"TO_PAY":@"买家待付款",
                          @"PAYED":@"买家已付款",
                          @"RECEIVING":@"取货中",
                          @"SENDING":@"发货中",
                          @"COMFIRM_RECEIVE":@"已确认收货",
                          @"APPLY_REFUND":@"申请退款",
                          @"REFUNDING":@"退款中",
                          @"REFUNDED":@"已退款",
                          @"CANCEL":@"已取消",
                          @"CLOSED":@"已关闭"};
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (self.notRefreshHome) {
        
    } else {
        if (self.selectIndex != 0) {
            UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
            btn.tag = self.selectIndex;
            [_ninaPagerView.pagerView touchAction:btn];
            nowPage = self.selectIndex;
            self.selectIndex = 0;
        } else {
            for (UITableView *tableView in _vcsArray) {
                if (tableView.tag == nowPage + 101) {
                    [tableView.mj_header beginRefreshing];
                    break;
                }
            }
        }
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark Private method

- (void)reloadData:(id) sender andTag:(NSUInteger) tag {
    if (lastTag != tag) {
        _curPage = 0;
    }
    lastTag = tag;
    _curPage = sender == self ? 1 : _curPage + 1;
    NSString *url;
    // TO_PAY,PAYED,RECEIVING,SENDING,COMFIRM_RECEIVE,APPLY_REFUND,  ,REFUNDED,CANCEL,CLOSED
    switch (tag) {
        case 101:// 全部
            url = [NSString stringWithFormat:@"%@%@?userId=%@&currentPage=%ld&pageSize=%d",
                   [BDNetworking shareInstance].baseUrl,
                   Order_Query,
                   [BDAccountManagerModel shareInstance].userId,
                   (long)_curPage,
                   kPageSize];
            break;
        case 102:// 待付款
            url = [NSString stringWithFormat:@"%@%@?status=%@&userId=%@&currentPage=%ld&pageSize=%d",
                   [BDNetworking shareInstance].baseUrl,
                   Order_Query,
                   @"TO_PAY",
                   [BDAccountManagerModel shareInstance].userId,
                   (long)_curPage,
                   kPageSize];
            break;
        case 103:// 待发货
            url = [NSString stringWithFormat:@"%@%@?status=%@,%@&userId=%@&currentPage=%ld&pageSize=%d",
                   [BDNetworking shareInstance].baseUrl,
                   Order_Query,
                   @"PAYED",@"RECEIVING",
                   [BDAccountManagerModel shareInstance].userId,
                   (long)_curPage,
                   kPageSize];
            break;
        case 104:// 待收货
            url = [NSString stringWithFormat:@"%@%@?status=%@&userId=%@&currentPage=%ld&pageSize=%d",
                  [BDNetworking shareInstance].baseUrl,
                  Order_Query,
                  @"SENDING",
                  [BDAccountManagerModel shareInstance].userId,
                  (long)_curPage,
                  kPageSize];
            break;
        case 105:// 已收货
            url = [NSString stringWithFormat:@"%@%@?status=%@&userId=%@&currentPage=%ld&pageSize=%d",
                   [BDNetworking shareInstance].baseUrl,
                   Order_Query,
                   @"COMFIRM_RECEIVE",
                   [BDAccountManagerModel shareInstance].userId,
                   (long)_curPage,
                   kPageSize];
            break;
        default:
            break;
    }
    if (url) {
        [[BDNetworking shareInstance] postWithUrl:url sid:nil method:@"GET" parameters:nil completionHandler:^(NSObject *results, NSError *error) {
            for (UITableView *tableView in _vcsArray) {
                if (tableView.tag == tag) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if ([tableView.mj_header isRefreshing]) {
                            [tableView.mj_header endRefreshing];
                        }
                        if ([tableView.mj_footer isRefreshing]) {
                            [tableView.mj_footer endRefreshing];
                        }
                    });
                }
            }
            if (error != nil) {
                NSLog(@"tag->订单查询失败:%lu%@",(unsigned long)tag,error);
                if ([[error localizedDescription] isEqualToString:@"登录超时"] && error.code == 401) {
                    [MBProgressHUD showToast:self.view withText:@"登录超时，请重新登录"];
                    if (!presentLoginView) {
                        presentLoginView = YES;
                        // 清除webViw cookie
                        NSHTTPCookie *cookie;
                        NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
                        for (cookie in [storage cookies])
                        {
                            [storage deleteCookie:cookie];
                        }
                        
                        [BDAccountManagerModel shareInstance].authorization = @"";
                        [BDAccountManagerModel shareInstance].login = NO;
                        UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
                        BDNavigationController *nav_addrVc = [stroyboard instantiateViewControllerWithIdentifier:@"navLoginStoryboardID"];
                        [self presentViewController:nav_addrVc animated:YES completion:nil];
                    }
                }
            } else {
                for (UITableView *tableView in _vcsArray) {
                    if (tableView.tag == tag) {
                        if ([results isKindOfClass:[NSDictionary class]]) {
                            NSLog(@"results = %@",results);
                            NSDictionary *resultDic = (NSDictionary *)results;
                            NSArray *resultList = resultDic[@"objects"];
                            if ([resultList count] > 0) {
                                tableView.mj_footer.hidden = [resultList count] == kPageSize ? NO : YES;
                                if (sender == self) {
                                    [_OrderList removeAllObjects];
                                }
                                [_OrderList addObjectsFromArray:resultList];
                            } else {
                                if (_curPage > 1) { // 分页引起的刷新
                                    dispatch_async(dispatch_get_main_queue(), ^{
                                        [tableView.mj_footer endRefreshingWithNoMoreData];
                                    });
                                } else { // 刷新之前的数据应该清零
                                    [_OrderList removeAllObjects];
                                }
                            }
                            dispatch_async(dispatch_get_main_queue(), ^{
                                [tableView reloadData];
                            });
                            
                        }
                        break;
                    }
                }
                
            }
        }];
    }
}

- (void)tableViewSettings {
    self.tableView1 = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView2 = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView3 = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView4 = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView5 = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    
    
    NSArray *titleArray =   @[@"全部",@"待付款",@"待发货",@"待收货",@"已收货"];
    _vcsArray = @[self.tableView1,self.tableView2,self.tableView3,self.tableView4,self.tableView5];
    NSArray *colorArray = @[
                            RGBColor(255, 78, 16), /** 选中的标题颜色 **/
                            RGBColor(51, 51, 51), /** 未选中的标题颜色 **/
                            RGBColor(255, 78, 16), /** 下划线颜色 **/
                            ];
    
    NSUInteger index = 101;
    for (UITableView *tableView in _vcsArray) {
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.tag = index;
        tableView.backgroundColor = RGBColor(238, 238, 238);
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        // 注册刷新头部和尾部
        tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [self reloadData:self andTag:index];
        }];
        //typeof(tableView.mj_footer) __weak footer = tableView.mj_footer;
        tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            // 多线程情况下footer可能为空
            [self reloadData:nil andTag:index];
        }];
        
        index++;
    }
    _ninaPagerView = [[NinaPagerView alloc] initWithTitles:titleArray WithVCs:_vcsArray WithColorArrays:colorArray];
    _ninaPagerView.delegate = self;
    [self.view addSubview:_ninaPagerView];
}

#pragma mark - NinaPagerViewDelegate

- (void)refreshTableView:(NSUInteger)page {
    nowPage = page;
    for (UITableView *tableView in _vcsArray) {
        if (tableView.tag == page + 101) {
            [_OrderList removeAllObjects];// 不然之前的数据会填入tableView
            [tableView.mj_footer resetNoMoreData];// 还原为普通状态
            [tableView.mj_header beginRefreshing];
        }
    }
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (_OrderList.count > 0) {
        return _OrderList.count;
    } else {
        return 1;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (_OrderList.count > 0) {
        NSArray *goodList = _OrderList[section][@"orderCommodities"];
        return goodList.count;
    } else {
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (_OrderList.count > 0) {
        OrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"orderCell"];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"OrderCell" owner:nil options:nil] lastObject];
        }
        
        cell.delegate = self;
        
        NSArray *goodList = _OrderList[indexPath.section][@"orderCommodities"];
        // 商品图片
        NSString *storeImageUrl = goodList[indexPath.row][@"commodity"][@"icon"];
        UIImageView *storeImageView = (UIImageView *)[cell viewWithTag:101];
        if (![storeImageUrl isEqual:[NSNull null]]) {
            [storeImageView sd_setImageWithURL:[NSURL URLWithString:storeImageUrl] placeholderImage:[UIImage imageNamed:@"imageUser_no"]];
        }
        // 商品名称
        UITextView *goodDescTextView = (UITextView *)[cell viewWithTag:102];
        NSString *goodDesc = goodList[indexPath.row][@"commodity"][@"name"];
        if (![goodDesc isEqual:[NSNull null]]) {
            goodDescTextView.text = goodDesc;
        }
        // 商品现价
        UILabel *priceNowLabel = (UILabel *)[cell viewWithTag:103];
        NSString *goodNowPrice = goodList[indexPath.row][@"price"];
        if (![goodNowPrice isEqual:[NSNull null]]) {
            priceNowLabel.text = [NSString stringWithFormat:@"¥ %.2f",[goodNowPrice floatValue]];
        }
        // 商品个数
        UILabel *numLabel = (UILabel *)[cell viewWithTag:104];
        NSString *goodNum = goodList[indexPath.row][@"num"];
        if (![goodNum isEqual:[NSNull null]]) {
            numLabel.text = [NSString stringWithFormat:@"x %ld",(long)[goodNum integerValue]];;
        }
        // 申请退货
        UIButton *refundBtn = [(UIButton *)cell viewWithTag:105];
        NSString *orderStatus = _OrderList[indexPath.section][@"status"];
        NSString *goodStatus = goodList[indexPath.row][@"status"];
        if ([orderStatus isEqualToString:@"TO_PAY"] ||
            [orderStatus isEqualToString:@"CLOSED"] ||
            [orderStatus isEqualToString:@"CANCEL"]) {
            [refundBtn setHidden:YES];
        } else {
            NSNumber *availableRefund = goodList[indexPath.row][@"availableRefund"];
            if (![availableRefund isEqual:[NSNull null]] &&
                availableRefund != nil &&
                [availableRefund integerValue] == 1) {
                [refundBtn setHidden:NO];
            } else {
                [refundBtn setHidden:YES];
            }
        }
        
        
        if ([goodStatus isEqualToString:@"NORMAL"] ||
            [goodStatus isEqualToString:@"REFUSE_REFUND"]) {// 正常状态 拒绝退款
            [refundBtn setTitle:@"申请退款" forState:UIControlStateNormal];
        } else {
            NSString *statusStr;
            if ([goodStatus isEqualToString:@"APPLY_REFUND"]) {
                statusStr = @"已申请退款";
            }
            if ([goodStatus isEqualToString:@"REFUNDING"]) {
                statusStr = @"退款中";
            }
            if ([goodStatus isEqualToString:@"REFUND"]) {
                statusStr = @"已退款";
            }
            [refundBtn setTitle:statusStr forState:UIControlStateNormal];
            
        }
        return cell;
    } else {
        OrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"orderNoneCell"];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"OrderNoneCell" owner:nil options:nil] lastObject];
        }
        return cell;
    }
}

#pragma mark - Tableview delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat cellHeight = 100.0;
    if (_OrderList.count > 0) {
        NSArray *goodList = _OrderList[indexPath.section][@"orderCommodities"];
        NSString *goodDesc = goodList[indexPath.row][@"commodity"][@"name"];
        if (![goodDesc isEqual:[NSNull null]]) {
            cellHeight = [goodDesc boundingHeightWithSize:CGSizeMake(kScreen_Width - 104.0, CGFLOAT_MAX) font:[UIFont systemFontOfSize:12.0] lineSpace:8.0] + 55;
            cellHeight = cellHeight < 100 ? 100 : cellHeight;
            NSLog(@"goodDesc %@ \n cellHeight = %f",goodDesc,cellHeight);
        }
    }
    return _OrderList.count > 0 ? cellHeight : kScreen_Height - 64 - .0675 * kScreen_Height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return _OrderList.count > 0 ? 35.0 : 0.1;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (_OrderList.count > 0) {
        UIView *header = [[[NSBundle mainBundle] loadNibNamed:@"orderHeader" owner:nil options:nil] lastObject];
        
        // 商店名称
        NSString *storeName = _OrderList[section][@"store"][@"name"];
        if (![storeName isEqual:[NSNull null]]) {
            ((UILabel *)[header viewWithTag:101]).text = storeName;
        }
        // 订单当前状态
        UILabel *statusLabel = (UILabel *)[header viewWithTag:102];
        NSString *orderStatus = _OrderList[section][@"status"];
        
        if ([statusDic valueForKey:orderStatus] &&
            ![orderStatus isEqual:[NSNull null]]) {
            statusLabel.text = statusDic[orderStatus];
        }
        
        return header;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return _OrderList.count > 0 ? 30.0 : 0.1;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (_OrderList.count > 0) {
        BDOrderFooter *footer = [[[NSBundle mainBundle] loadNibNamed:@"orderFooter" owner:nil options:nil] lastObject];
        footer.tag = section;
        footer.delegate = self;
        
        NSString *orderStatus = _OrderList[section][@"status"];
        // 商品价格
        UILabel *goodPriceLabel = (UILabel *)[footer viewWithTag:107];
        NSString *commodityPrice = _OrderList[section][@"commodityPrice"];
        NSString *expressPrice = _OrderList[section][@"expressPrice"];
        if (![commodityPrice isEqual:[NSNull null]] &&
            ![expressPrice isEqual:[NSNull null]] &&
            [goodPriceLabel isKindOfClass:[UILabel class]]) {
            goodPriceLabel.text = [NSString stringWithFormat:@"¥ %.2f",[commodityPrice floatValue] + [expressPrice floatValue]];
        }
        // 右下角按钮
        UIButton *button1 = (UIButton *)[footer viewWithTag:108];
        UIButton *button2 = (UIButton *)[footer viewWithTag:109];
        button1.hidden = NO;
        button2.hidden = NO;
        
        if ([statusDic valueForKey:orderStatus] &&
            ![orderStatus isEqual:[NSNull null]]) {
            if ([orderStatus isEqualToString:@"TO_PAY"]) {// 待付款
                button1.hidden = YES;
                button2.hidden = YES;
            }
            if ([orderStatus isEqualToString:@"PAYED"] ||
                [orderStatus isEqualToString:@"RECEIVING"]) {// 待发货
                button1.hidden = YES;
                button2.hidden = YES;
            }
            if ([orderStatus isEqualToString:@"SENDING"]) {// 待收货
                [button1 setTitle:@"查看物流" forState:UIControlStateNormal];
                [button2 setTitle:@"确认收货" forState:UIControlStateNormal];
                [button2 setBackgroundImage:[UIImage imageNamed:@"order_roundRectButton3"] forState:UIControlStateNormal];
                [button2 setTitleColor:RGBColor(255, 255, 255) forState:UIControlStateNormal];
            }
            if ([orderStatus isEqualToString:@"COMFIRM_RECEIVE"]) {// 已收货
                button1.hidden = YES;
                [button2 setTitle:@"评价" forState:UIControlStateNormal];
                [button2 setBackgroundImage:[UIImage imageNamed:@"order_roundRectButton3"] forState:UIControlStateNormal];
                [button2 setTitleColor:RGBColor(255, 255, 255) forState:UIControlStateNormal];
            }
            if ([orderStatus isEqualToString:@"CANCEL"]) {// 已取消
                button1.hidden = YES;
                button2.hidden = YES;
            }
            if ([orderStatus isEqualToString:@"CLOSED"]) {// 已关闭
                button1.hidden = YES;
                button2.hidden = YES;
            }
        }
        
        return footer;
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (_OrderList.count > 0) {
        NSDictionary *dic = _OrderList[indexPath.section];
        UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        
        BDOrderDetailViewController *detailVC = [stroyboard instantiateViewControllerWithIdentifier:@"OrderDetailStoryboardID"];
        detailVC.order = dic;
        [self.navigationController pushViewController:detailVC animated:YES];
    }
}

#pragma mark - BDOrderFooterDelegate

- (void)pushToNewViewController:(UIView *)sender name:(NSString *)name {
    UIView *superView = sender.superview;
    while (![superView isKindOfClass:[BDOrderFooter class]]) {
        superView = superView.superview;
    }
    BDOrderFooter *footer = (BDOrderFooter *)superView;
    
    NSString *orderId = _OrderList[footer.tag][@"orderId"];
    NSArray *commodities = _OrderList[footer.tag][@"orderCommodities"];
    
    UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    if ([name isEqualToString:@"查看物流"]) {
        NSString *expressType = _OrderList[footer.tag][@"expressType"];
        if (![expressType isEqual:[NSNull null]]) {
            if ([expressType isEqualToString:@"ONESELF"]) {
                [MBProgressHUD showToast:self.view withText:@"商品为自取,无法查看物流"];
                return;
            }
        }
        BDTransformViewController *trans_vc = [stroyboard instantiateViewControllerWithIdentifier:@"TransformStoryboardID"];
        trans_vc.orderId = orderId;
        [self.navigationController pushViewController:trans_vc animated:YES];
    }
    if ([name isEqualToString:@"评价"]) {
        BDEvaluationViewController *eva_vc = [stroyboard instantiateViewControllerWithIdentifier:@"EvaluationStoryboardID"];
        eva_vc.orderId = orderId;
        eva_vc.commodities = commodities;
        [self.navigationController pushViewController:eva_vc animated:YES];
    }
    
}

- (void)confirmReceive:(UIView *)sender {
    UIView *superView = sender.superview;
    while (![superView isKindOfClass:[BDOrderFooter class]]) {
        superView = superView.superview;
    }
    BDOrderFooter *footer = (BDOrderFooter *)superView;
    for (UITableView *tableView in _vcsArray) {
        if (tableView.tag == nowPage + 101) {
            
            NSString *orderId = _OrderList[footer.tag][@"orderId"];
            MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view withText:@"确认收货中"];
            
            NSString *url = [NSString stringWithFormat:@"%@%@?orderId=%@",[BDNetworking shareInstance].baseUrl,Order_Receive,orderId];
            [[BDNetworking shareInstance] postWithUrl:url sid:nil method:@"PUT" parameters:nil completionHandler:^(NSObject *results, NSError *error) {
                if (error != nil) {
                    NSLog(@"确认收货失败:%@",error);
                    hud.labelText = @"确认收货失败";
                    [hud hideAfterDelay:0.5];
                } else {
                    [hud hideAfterDelay:0.5];
                    NSLog(@"result = %@",results);
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        [tableView.mj_header beginRefreshing];
                    });
                }
            }];
            
            break;
        }
    }
}

#pragma mark OrderTableViewCellDelegate

- (void)applyRefund:(UIView *)sender {
    UIView *superView = sender.superview;
    while (![superView isKindOfClass:[UITableViewCell class]]) {
        superView = superView.superview;
    }
    UITableViewCell *cell = (UITableViewCell *)superView;
    for (UITableView *tableView in _vcsArray) {
        if (tableView.tag == nowPage + 101) {
            NSIndexPath *indexPath = [tableView indexPathForCell:cell];
            NSArray *goodList = _OrderList[indexPath.section][@"orderCommodities"];
            UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
            BDRefundViewController *refund_vc = [stroyboard instantiateViewControllerWithIdentifier:@"RefunStoryboardID"];
            refund_vc.goodList = goodList;
            refund_vc.block = ^(NSString *str){
                if ([str isEqualToString:@"success"]) {
                    
                }
            };
            [self.navigationController pushViewController:refund_vc animated:YES];
        }
    } 
}


#pragma mark - IBActions

- (IBAction)backButtonPressed:(UIBarButtonItem *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)homeButtonPressed:(UIBarButtonItem *)sender {
    self.block(@"success");
    [self dismissViewControllerAnimated:YES completion:nil];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
